/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.controller;

/**
 *
 * @author Laurent WOUTERS
 */
public class Variable extends ASTElement {
    protected boolean inline;
    protected Element child;
    protected xowl.gmi.view.diagram.Widget widget;
    protected xowl.gmi.view.diagram.SelectableWidget selectable;
    
    public Variable(Controller controller, Element parent, xowl.gmi.model.ast.ASTNode ast, boolean inline) {
        super(controller, parent, ast);
        this.inline = inline;
    }
    
    public void setChild(Element child) {
        this.child = child;
        if (inline) {
            this.widget = child.getWidget();
        } else {
            this.selectable = new xowl.gmi.view.diagram.SelectableWidget(this, controller.getLocale());
            this.selectable.setChild(child.getWidget());
            this.widget = this.selectable;
            setupExecution(selectable);
        }
    }
    
    @Override protected void onChildAdd(xowl.gmi.model.ast.ASTNode node) { child.insertAST(node); }
    @Override protected void onChildRemove(xowl.gmi.model.ast.ASTNode node) { child.removeAST(node); }
    
    @Override public xowl.gmi.view.diagram.Widget getWidget() { return widget; }
    
    @Override public void saveTo(xowl.gmi.model.Diagram diagram) {
        child.saveTo(diagram);
    }
    @Override public void decommission() {
        this.decommissionListeners();
        child.decommission();
    }
}
